package com.yihu.cms.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.yihu.article.beans.Article;
import com.yihu.beans.ResultVO;
import com.yihu.beans.dic.ResultCode;
import com.yihu.beans.dic.DatadicQuery;
import com.yihu.cms.service.ArticleService;
import com.yihu.cms.service.DataDictionaryService;
import com.yihu.cms.util.CommonUtils;

@Controller
public class DataDicResultCodeController {
private final Logger logger = LoggerFactory.getLogger(DataDicResultCodeController.class); 
	DataDictionaryService service = new DataDictionaryService();
	
	@RequestMapping(value = "/datadic/resultCode", method = RequestMethod.POST)
	public @ResponseBody Object add(@RequestBody ResultCode resultCode) {
		logger.debug("/datadic/resultCode.add: "+resultCode);
		ResultVO result = service.addDataResultCode(resultCode);
		return JSON.toJSONString(result);
	}
	
	@RequestMapping(value = "/datadic/resultCode/{id}", method = RequestMethod.DELETE)
	public @ResponseBody Object delete(@PathVariable("id") String id) {
		logger.debug("/datadic/resultCode.delete: "+id);
		ResultCode resultCode = new ResultCode();
		resultCode.setId(id);
		ResultVO result = service.deleteDataResultCode(resultCode);
		return JSON.toJSONString(result);
	}
	
	@RequestMapping(value = "/datadic/resultCode/{id}", method = RequestMethod.GET)
	public @ResponseBody Object getResultCode(@PathVariable("id") String id) {
		logger.debug("getResultCode: "+id);
		ResultCode resultCode = new ResultCode();
		resultCode.setId(id);
		Object o = service.getDataResultCode(resultCode);
		return JSON.parse(JSON.toJSONString(o));
	}
	
	
	@RequestMapping(value = "/datadic/resultCode/{id}", method = RequestMethod.PUT)
	public @ResponseBody Object update(@RequestBody ResultCode resultCode,@PathVariable("id") String id) {
		resultCode.setId(id);
		logger.debug("/datadic/resultCode.update: "+resultCode);
		ResultVO result = service.updateDataResultCode(resultCode);
		return JSON.toJSONString(result);
	}
	
	@RequestMapping(value = "/datadic/resultCodes", method = RequestMethod.GET)
	public @ResponseBody Object getResultCodesByParent(DatadicQuery query) {
		logger.debug("getResultCodesByParent: "+query);
		Object o = service.getDataResultCodes(query);
		return JSON.parse(JSON.toJSONString(o));
	}
	
}
